<?php

namespace App\Http\Livewire;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;
use Livewire\Component;

class WelcomePage extends Component
{

    public $email;
    public $password;
    public $rememberMe;

    protected $rules = [
        'email' => 'bail|required|email',
        'password' => 'bail|required'
    ];

    public function logIn(Request $request){

        $this->validate();

        if (Auth::attempt(['email' => $this->email, 'password' => $this->password], $this->rememberMe)) {
            $request->session()->regenerate();
            return redirect()->route('user-profile', ['userName' => Auth::user()->user_name]);
        }

        $this->addError('email', Lang::get('auth.failed'));
    }

    public function render()
    {
        return view('livewire.welcome-page');
    }
}
